/*************************************************************************
	> File Name: P1115.cpp
	> Author: 
	> Mail: 
	> Created Time: 
 ************************************************************************/
#include <iostream>
using namespace std;

const int INF = 0x7fffffff;

int main() {
    int n; cin >> n;
    int maxsum = -INF;
    int start = 1, end = 1, p = 1, sum = 0;
    for (int i = 1; i <= n; i++) {
        int a; cin >> a; sum += a;
        if (sum > maxsum) {
            maxsum = sum;
            start = p;
            end = i;
        }
        if (sum < 0) {
            sum = 0;
            p = i + 1;
        }
    }
    cout << maxsum << endl;
    return 0;
}
